﻿using System;
using System.Collections.Generic;
using System.Windows.Browser;
using System.Windows.Controls;

namespace SilentWebsite.ViewModels.Helpers
{
    public static class NavigationService
    {
        public static Frame Frame { get; set; }
        public static Dictionary<string, string> Pages { get; set; }
        public static Dictionary<string, string> Links { get; set; }

        static NavigationService()
        {
            Pages = new Dictionary<string, string>();
            Links = new Dictionary<string, string>();
        }

        public static void Back()
        {
            if (Frame == null)
                throw new NullReferenceException();

            Frame.GoBack();
        }
        public static bool Navigate(string name, NavigationPageType type = NavigationPageType.SilverlightPage)
        {
            if (Frame == null)
                throw new NullReferenceException();

            var upperName = name.ToUpper();

            switch (type)
            {
                case NavigationPageType.SilverlightPage:
                    return Frame.Navigate(new Uri(Pages[upperName], UriKind.Relative));;
                case NavigationPageType.HttpLink:
                    HtmlPage.Window.Navigate(new Uri(Links[upperName], UriKind.Absolute));
                    return true;
            }
            
            return false;
        }
    }

    public enum NavigationPageType
    {
        SilverlightPage,
        HttpLink
    }
}
